/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tr.edu.ozyegin.ccrg.raid.test;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;

import tr.edu.ozyegin.ccrg.raid.monitor.SystemMonitor;
/**
 *
 * @author becomen
 */
public class SystemStat {
    public static void main(String[] args) throws FileNotFoundException, IOException{
        DecimalFormat format = new DecimalFormat("#00.00");
        for(;;){
            FileInputStream html = new FileInputStream("html/pieChart.htm");
            //System.out.println("geldim2");
            DataInputStream htmlDs = new DataInputStream(html);
            String htmlStr = "";
            String tmp;
            while((tmp = htmlDs.readLine())!=null)htmlStr+=tmp+"\n";
            htmlDs.close();
            html.close();
            double cpu = SystemMonitor.getCPU()*100;
            Integer result = (int)(cpu);
            htmlStr = htmlStr.replace("$CPU$", result.toString());
            double memory = SystemMonitor.getMemory()*100;
            result = (int)(memory);
            htmlStr = htmlStr.replace("$MEMORY$", result.toString());
            //System.out.println("geldim");
            FileOutputStream stout = new FileOutputStream("html/pieData.htm");
            stout.write(htmlStr.getBytes());
            stout.close();
            System.out.printf("\rCpu usage: \033[0;32m%6.2f%%\033[0m Memory usage: \033[0;32m%6.2f%%\033[0m",cpu,memory);
            System.out.flush();
        }
    }

    private static int getMemory() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
